﻿using System;
using System.Collections.Generic;
using Entalpy.dto;
using System.IO;
using System.Text;

namespace Entalpy.Model
{
    public class DataReader : IDataReader
    {
        public IList<Data> ReadData(string path)
        {
            string Line;
            string[] strArr;
            char[] charArr = new char[] { ';' }; // используемый в файле разделитель
            IList<Data> Data = new List<Data>();
            try
            {
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    StreamReader sr = new StreamReader(fs, Encoding.Default);
                    while (sr.EndOfStream != true)
                    {
                        Line = sr.ReadLine();
                        strArr = Line.Split(charArr);

                        Data data = new Data();
                        try
                        {
                            data.Mass = (strArr[0] != "") ? Convert.ToDouble(strArr[0]) : 0;
                            data.Intensity = (strArr[1] != "") ? Convert.ToDouble(strArr[1]) : 0;
                            data.Temperature = (strArr[2] != "") ? Convert.ToDouble(strArr[2]) : 0;
                            data.Heating = (strArr[3] != "") ? Convert.ToDouble(strArr[2]) : 0;
                        }
                        catch (Exception ex) { }

                        Data.Add(data);

                    }
                    sr.Close();
                }
            }
            catch (Exception ex) { return null; }
            return Data;

        }

      
    }
}
